package me.zfz.business.controller.impl;

import javax.servlet.http.HttpServletRequest;

import me.zfz.base.bean.SmartResponse;
import me.zfz.base.constant.IConstant;
import me.zfz.business.bean.entity.TNAttachment;
import me.zfz.business.controller.base.AttachmentUploadController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * 上传图片[测试类]
 *
 * @author author
 */
@Controller
@RequestMapping("/pictrue")
public class PicUploapController extends AttachmentUploadController {

    @RequestMapping("/upload")
    public @ResponseBody
    SmartResponse<TNAttachment> upload(@RequestParam MultipartFile file, HttpServletRequest request) throws Exception {
        SmartResponse<TNAttachment> smartResp = new SmartResponse<TNAttachment>();
        if (null != file) {
            String userId = getUserInfoFromSession(request).getId();
            TNAttachment att = attUploadHandler.fileUpload(file.getInputStream(), file.getContentType(), file.getOriginalFilename(), file.getSize(), userId);
            if (null != att) {
                smartResp.setResult(IConstant.OP_SUCCESS);
                smartResp.setMsg(IConstant.OP_SUCCESS_MSG);
                smartResp.setData(att);
            }
        }
        return smartResp;
    }

}
